/*************************************************************************
 * File Name:    2777.cc
 * Author:       zero91
 * Mail:         jianzhang9102@gmail.com
 * Created Time: Sat 28 Sep 2013 11:06:55 AM CST
 * 
 * Description:  http://poj.org/problem?id=2777
 ************************************************************************/

#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>

using namespace std;

#define MAXL 100010

struct tree_node {
    int left, right;
    int color, color_cnt;
};

struct tree_node tree[MAXL << 2];

inline int
bit_cnt(int num)
{
    int ans = 0;
    while (num > 0) {
        ++ans;
        num &= num - 1;
    }
    return ans;
}

void
build_tree(int root, int left, int right)
{
    tree[root].left = left;
    tree[root].right = right;
    tree[root].color = 1;
    tree[root].color_cnt = 1;

    if (left == right) return;
    int mid = left + ((right - left) >> 1);

    build_tree(root << 1, left, mid);
    build_tree(root << 1 | 1, mid + 1, right);
}

inline void
push_down(int root)
{
    if (tree[root].color_cnt != 1) return;
    tree[root << 1].color = tree[root].color;
    tree[root << 1].color_cnt = 1;
    tree[root << 1 | 1].color = tree[root].color;
    tree[root << 1 | 1].color_cnt = 1;
}

inline void
push_up(int root)
{
    tree[root].color = tree[root << 1].color | tree[root << 1 | 1].color;
    tree[root].color_cnt = bit_cnt(tree[root].color);
}

void
update_tree(int root, int left, int right, int color)
{
    if (left <= tree[root].left && tree[root].right <= right) {
        tree[root].color = 1 << (color - 1);
        tree[root].color_cnt = 1;
        return;
    }
    push_down(root);
    int mid = (tree[root].left + tree[root].right) >> 1;
    
    if (right <= mid) update_tree(root << 1, left, right, color);
    if (left > mid) update_tree(root << 1 | 1, left, right, color);

    push_up(root);
}

int
query(int root, int left, int right)
{
    if (left <= tree[root].left && tree[root].right <= right) {
        return tree[root].color;
    }
    int mid = (tree[root].left + tree[root].right) >> 1;
    if (right <= mid) return query(root << 1, left, right);
    else if (left > mid) return query(root << 1 | 1, left, right);
    else {
        return query(root << 1, left, right) | query(root << 1 | 1, left, right);
    }
}

int
main(int argc, char *argv[])
{
#ifndef ONLINE_JUDGE
    freopen("input", "r", stdin);
#endif
    int L, T, O;
    int A, B, C;
    char type;

    scanf("%d %d %d", &L, &T, &O);
    build_tree(1, 1, L);

    while (O--) {
        scanf(" %c", &type);
        if (type == 'C') {
            scanf("%d %d %d", &A, &B, &C);
            update_tree(1, A, B, C);

        } else if (type == 'P') {
            scanf("%d %d", &A, &B);
            printf("%d\n", bit_cnt(query(1, A, B)));
        }
    }
    return 0;
}
